﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using HiSun.Components;

namespace Hisun.Components
{
    public class SiteSettingManager
    {

        public static SiteSettings GetSiteSetting(string siteurl)
        {
            siteurl = siteurl.ToLower();
            Hashtable ht = GetActiveSiteSettings();
            SiteSettings settings = ht[siteurl] as SiteSettings;
            if (settings == null)
            {

                settings = LoadSiteSettings();
                if (settings != null)
                {
                    lock (ht.SyncRoot)
                    {
                        if (!ht.Contains(siteurl))
                            ht.Add(siteurl, settings);

                    }
                }
                else
                {
                    throw new Exception("未注册的应用程序");
                }


            }
            return settings;

        }

        public static SiteSettings LoadSiteSettings()
        {
           
            SiteSettings sitSetings = new SiteSettings();
            sitSetings.Title = "中国农业银行-客户批量升级平台";
            sitSetings.Description = "中国农业银行-客户批量升级平台";
            sitSetings.CssName = "/Themes/Default/Style/css-red.css"; //"/Themes/Default/Style/css-red.css"; //




            return sitSetings;
        }

        /// <summary>
        /// 取得缓存中的SiteSettings值
        /// </summary>
        /// <returns></returns>
        public static Hashtable GetActiveSiteSettings()
        {
            const string siteSettingsCacheKey = "SiteSettings";
            Hashtable ht = HiSunCache.Get(siteSettingsCacheKey) as Hashtable;
            if (ht == null)
            {
                ht = new Hashtable();
                HiSunCache.Insert(siteSettingsCacheKey, ht, null, HiSunCache.MinuteFactor * 15);
            }
            return ht;
        }
    }
}
